<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>注册</title>
    <script type="text/javascript" src="../js/jquery-3.5.1.js"></script>
    <script type="text/javascript" src="../js/base.js"></script>
</head>
<body>
<table align="center" border="1">
    <caption>注册</caption>
    <tr>
        <td>用户名</td>
        <td><input name="username" type="text"></td>
    </tr>
    <tr>
        <td>密码</td>
        <td><input name="password" type="password"></td>
    </tr>
    <tr>
        <td colspan="2">
            <button id="sub">提交</button>
        </td>
    </tr>
</table>
<script>
    $(function () {
        //当点击提交时
        $("#sub").on("click", function () {
            let username = $("input[name=username]").val()
            let password = $("input[name=password]").val()
            let data = {username:username,password:password}
            //进行ajax提交
            $.ajax({
                url:baseUrl+"/web02/ajax_register",
                type:"POST",
                contentType:"application/json",
                dataType:"json",
                data:JSON.stringify(data),
                success:function (data){
                    console.log(data)
                    if(data.code==200){
                        alert("注册成功")
                        window.location.href="login.jsp"
                    }else{
                        alert(data.msg)
                    }
                },
                error:function (e){
                    console.log(e)
                }
            })

        })
    })
</script>
</body>
</html>
